package com.zyh.cxf;


import com.zyh.dao.KeyMapper;
import com.zyh.util.RandomNumber;
import com.zyh.util.safeutil.DESedeUtil;
import com.zyh.util.safeutil.SM2Utils;
import com.zyh.util.safeutil.Util;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;

@Controller
public class TestFundPayOrder {

    //行wai转账
    @Test
    public void TestgetFundPayOrder(){
        try {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();

        jaxWsProxyFactoryBean.setAddress("http://10.229.1.149:8091/ssm/webservices/getFundPayOrder");
        //jaxWsProxyFactoryBean.setAddress("http://localhost:8080/ssm/webservices/getFundPayOrder");


        jaxWsProxyFactoryBean.setServiceClass(FundPayOrderService.class);

        FundPayOrderService fundPayOrderService  = (FundPayOrderService) jaxWsProxyFactoryBean.create();
        Document doc = DocumentHelper.createDocument();
        Element Message = doc.addElement("Message");
        Element Head = Message.addElement("Head");
        Element Body = Message.addElement("Body");


        Element serialNo = Head.addElement("serialNo");
        Element reqTime = Head.addElement("reqTime");
        Element bsnCode = Head.addElement("bsnCode");
        Element CifNo = Head.addElement("CifNo");

        serialNo.setText(RandomNumber.productTxnTm());
        reqTime.setText(RandomNumber.productTxnTm());
        bsnCode.setText(RandomNumber.productTxnTm());
        CifNo.setText(RandomNumber.productTxnTm());

        Element PayerAcNo=Body.addElement("PayerAcNo");
        Element PayeeAcNo=Body.addElement("PayeeAcNo");
        Element PayeeAcName=Body.addElement("PayeeAcName");
        Element Amount=Body.addElement("Amount");
        Element Currency=Body.addElement("Currency");
        Element UnionBankNo=Body.addElement("UnionBankNo");
        Element UnionBankName=Body.addElement("UnionBankName");
       // Element PayerAcName=Body.addElement("PayerAcName");

        PayerAcNo.setText("82010000000349355");//
        //PayerAcNo.setText("6230179700005029");//
        //PayeeAcNo.setText("82010000000350348");//        6230179500003513
        PayeeAcNo.setText("6251500880063088");//        6230179500003513
        //PayeeAcNo.setText("6230179500003513");//        6230179500003513

        //PayeeAcNo.setText("");//对公账户6227004402550003542
       // PayeeAcName.setText("多县杂人事劳动和社会保障局（医疗保险）");//王龙
        //PayeeAcName.setText("候文哲");//王龙
        PayeeAcName.setText("田洪知");//王龙
        Amount.setText("200");
        Currency.setText("CNY");
        UnionBankNo.setText("402871099996");
        UnionBankName.setText("中国邮政储蓄银行湟源支行");

        String xmlBody = doc.asXML();
        System.out.println(xmlBody);

        // 加密
        String inencryptStr = null;

            inencryptStr = DESedeUtil.encrypt(doc.asXML(), "4+oOg7N/0I wWa5uk41HlHINPXhAZByVd");
            String data = fundPayOrderService.getFundPayOrder(inencryptStr);

            System.out.println(DESedeUtil.decrypt(data, "4+oOg7N/0IwWa5uk41HlHINPXhAZByVd"));
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
